home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Graphics Samples / Spectacle ƒ / Object.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-15  |  2.7 KB  |  144 lines  |  [TEXT/KAHL]

  1. /*
  2.  *    Object.c
  3.  *
  4.  *    Robert Dierkes,  November 11, 1993
  5.  *
  6.  *    Change History:
  7.  *
  8.  *       11/93    ???        New
  9.  *       4/96        bob        Updated #includes to support changed GX Library names.
  10.  *                        Changed boolean to Boolean.
  11.  *                        Added the copyright info.
  12.  *
  13.  *
  14.  *        © Apple Computer, Inc. 1990 - 1996  All rights reserved
  15.  *
  16.  */
  17.  
  18. #include <GXGraphics.h>
  19. #include "GraphicsLibraries.h"
  20.  
  21. #include "ViewPorts.h"
  22. #include "Main.h"
  23. #include "Object.h"
  24.  
  25.  
  26. /*----------------------*/
  27. /*    Global Declarations    */
  28. /*----------------------*/
  29. gxPoint                gDistance;
  30. gxColor                gBackgroundColor;
  31.  
  32. /*------------------------------*/
  33. /*    External Declarations     */
  34. /*------------------------------*/
  35. extern    WindowPtr    gWindow;
  36. extern    gxShape        gFrame,
  37.                     gObject,
  38.                     gLastObject;
  39.  
  40.  
  41.  
  42. void SetSimpleColor (gxColor *pColor, commonColor someColor);
  43. void SetSimpleColor (gxColor *pColor, commonColor someColor)
  44. {
  45.     pColor->element.indexed.set   = commonColorSet;
  46.     pColor->element.indexed.index = someColor;
  47.     pColor->space   = gxIndexedSpace;
  48.     pColor->profile = nil;
  49.     pColor->element.rgb.red =
  50.     pColor->element.rgb.red =
  51.     pColor->element.rgb.red = 0xFFFF;
  52. }
  53.  
  54.  
  55. /*
  56.  *    Global:
  57.  *        gDistance
  58.  */
  59.     void
  60. InitializeObject (Boolean isSquare, Fixed width, Fixed height, gxShape *pObject, gxShape *pLastObject)
  61. {
  62.     gxRectangle    bounds;
  63.  
  64.     if (pObject == nil)
  65.     {
  66.         DebugStr ("\pInitializeObject: pObject is nil");
  67.         return;
  68.     }
  69.  
  70.     DisposeShapeAt (pObject);
  71.  
  72.     bounds.left   =
  73.     bounds.top    = 0;
  74.     bounds.right  = width;
  75.     bounds.bottom = height;
  76.  
  77.     *pObject = isSquare ? GXNewRectangle (&bounds) : NewOval (&bounds);
  78.  
  79.     GXMoveShapeTo (*pObject, fixed1, fixed1);
  80.     SetShapeCommonColor (*pObject, lamp_black);
  81.  
  82.     DisposeShapeAt (pLastObject);
  83.     *pLastObject = GXNewShape (gxEmptyType);
  84.     SetSimpleColor (&gBackgroundColor, gxWhite);
  85.  
  86.     gDistance.x = width  >> 3;
  87.     gDistance.y = height >> 3;
  88. }
  89.  
  90.  
  91. /*
  92.  *    Globals:
  93.  *        gDistance
  94.  *        gObject
  95.  *        gLastObject
  96.  */
  97.     void
  98. MoveObject (void)
  99. {
  100.     gxRectangle    bounds;
  101.  
  102.     GXGetShapeBounds (gObject, 0, &bounds);
  103.  
  104.     /* Change direction if object reaches window edge */
  105.     if (bounds.left <= 0  ||
  106.         bounds.right >= IntToFixed (gWindow->portRect.right))
  107.     {
  108.         gDistance.x = - gDistance.x;
  109.     }
  110.  
  111.     if (bounds.top <=  0  ||
  112.         bounds.bottom >= IntToFixed (gWindow->portRect.bottom))
  113.     {
  114.         gDistance.y = - gDistance.y;
  115.     }
  116.  
  117.     GXDisposeShape (gLastObject);
  118.     gLastObject = CopyShape (gObject);
  119.     GXSetShapeColor (gLastObject, &gBackgroundColor);
  120.  
  121.     /* Move and draw new object */
  122.     GXMoveShape (gObject, gDistance.x, gDistance.y);
  123.  
  124.     /* Erase portion of previous object */
  125.     GXDifferenceShape (gLastObject, gObject);
  126.     GXDrawShape (gLastObject);
  127.  
  128.     GXDrawShape (gObject);
  129. }
  130.  
  131.  
  132.     void
  133. DrawObject (void)
  134. {
  135.     GXDrawShape (gObject);
  136. }
  137.  
  138.  
  139.     void
  140. DrawObjectFrame (void)
  141. {
  142.     GXDrawShape (gFrame);
  143. }
  144.